package nl.nhl.idp.Views;

import android.content.Context;
import android.graphics.Color;
import android.graphics.PorterDuff.Mode;
import android.util.AttributeSet;
import android.widget.CompoundButton;
import android.widget.ToggleButton;

public class ZToggleButton extends ToggleButton
{
	private int checkedColor = Color.GREEN;
	public void SetCheckedColor(int color)
	{
		checkedColor = color;
		SetColor();
	}
	
	private int unCheckedColor = Color.RED;
	public void SetUnCheckedColor(int color)
	{
		unCheckedColor = color;
		SetColor();
	}
	
	public ZToggleButton(Context context, AttributeSet attrs, int defStyle)
	{
		super(context, attrs, defStyle);
		SetColor();
		setOnCheckedChangeListener(new CheckChanged());
	}
	public ZToggleButton(Context context, AttributeSet attrs)
	{
		this(context, attrs, 0);
	}
	public ZToggleButton(Context context)
	{
		this(context, null);
	}

	private void SetColor()
	{
		if(isChecked())
		{
			//checked style
			getBackground().setColorFilter(checkedColor, Mode.MULTIPLY);
		}
		else
		{
			//unchecked style
			getBackground().setColorFilter(unCheckedColor, Mode.MULTIPLY);
		}
	}
	
	public class CheckChanged implements OnCheckedChangeListener
	{

		public void onCheckedChanged(CompoundButton arg0, boolean arg1)
		{
			//set button color according to checked state
			SetColor();
		}
	}
}
